package com.xbfinal.myzhxy.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xbfinal.myzhxy.mapper.GradeMapper;
import com.xbfinal.myzhxy.pojo.Grade;
import com.xbfinal.myzhxy.service.GradeService;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.thymeleaf.util.StringUtils;

@Service("GradeServiceImpl")
@Transactional
public class GradeServiceImpl
        extends ServiceImpl<GradeMapper, Grade>
        implements GradeService {
    @Override
    public IPage<Grade> getBradeByOpr(Page<Grade> page, String gradeName) {
        QueryWrapper<Grade> queryWrapper=new QueryWrapper<>();
        //判断gradeName是否为空
        final boolean empty = StringUtils.isEmpty(gradeName);
        if(!empty){
            queryWrapper.like("name",gradeName);
        }
        //降序排序根据id
        queryWrapper.orderByDesc("id");

        final Page<Grade> page1 = baseMapper.selectPage(page, queryWrapper);
        //Page继承了IPage
        return page1;
    }
}
